package com.game.animation;

import com.game.utils.AnimationInterpolatorUtil;


/**
* @author oven:
* @version 创建时间：2012-11-15 下午6:06:10
* 
*/
public class AnimationScale  extends Animation{
	public static final int TYPE_SCALE_ONLY=0;//只放大
	public static final int TYPE_SCALE_RESTORE=1;//放大后还原
	
	public static final int TYPE_SCALE_SPEED_ACC=0;//加速
	public static final int TYPE_SCALE_SPEED_DEC=1;//减速

	protected float scalex;//x轴放大的比例
	protected float scaley;//y轴放大的比例
	protected int type;
	protected int speedType;
	public AnimationScale(AnimationFix animationfix,
			AnimationCallBack animationCallBack, float delayTime, boolean keep,
			float scalex,float scaley,float time,int type,int speedType) {
		super(animationfix, animationCallBack, delayTime, keep,time);
		this.scalex=scalex;
		this.scaley=scaley;
		this.type=type;
		this.speedType=speedType;
		this.animationType=ANIMATION_TYPE_SCALE;
	}

	@Override
	protected void step() {
		float input = 0;
		float perc=0;
		if(type==TYPE_SCALE_ONLY){
			input=time_step/time;
			if(speedType==TYPE_SCALE_SPEED_ACC){
				perc=AnimationInterpolatorUtil.getAccelerate(input);
			}else{
				perc=AnimationInterpolatorUtil.getDecelerate(input);
			}
			animationfix.setScalex(perc*scalex);
			animationfix.setScaley(perc*scaley);
		}else{
			if(time_step<=time/2){
				input = time_step/(time/2);
				if(speedType==TYPE_SCALE_SPEED_ACC){
					perc=AnimationInterpolatorUtil.getAccelerate(input);
				}else{
					perc=AnimationInterpolatorUtil.getDecelerate(input);
				}
				animationfix.setScalex(perc*scalex);
				animationfix.setScaley(perc*scaley);
			}else{
				input = (time_step-time/2)/(time/2);
				if(speedType==TYPE_SCALE_SPEED_ACC){
					perc=AnimationInterpolatorUtil.getAccelerate(input);
				}else{
					perc=AnimationInterpolatorUtil.getDecelerate(input);
				}
				animationfix.setScalex(scalex-perc*scalex);
				animationfix.setScaley(scaley-perc*scaley);
			}
		}
		
	}

	@Override
	protected void keepState() {
		// TODO Auto-generated method stub
		/**
		* @version 创建时间：2012-11-15 下午6:06:29
		* 
		*/
	}

}

